package sortTest;

import java.util.Random;

public class Top100 {

	public static int[] getTop100(int[] inputArray) {
		int maxValue = Integer.MIN_VALUE;
		for (int i = 0; i < inputArray.length; ++i) {
			if (maxValue < inputArray[i]) {
				maxValue = inputArray[i];
			}
		}
		byte[] bitmap = new byte[maxValue + 1];
		for (int i = 0; i < inputArray.length; ++i) {
			int value = inputArray[i];
			bitmap[value] = 1;
		}
		int[] result = new int[100];
		int index = 0;
		for (int i = maxValue; i >= 0 & index < 100; --i) {
			if (bitmap[i] == 1) {
				result[index++] = i;
			}
		}
		return result;
	}
	public static void main(String[] args) {
		int numberCount = 90000;
		int maxNumber = numberCount;
		int inputArray[] = new int[numberCount];
		Random random = new Random();
		for (int i = 0; i < numberCount; ++i) {
			inputArray[i] = Math.abs(random.nextInt(maxNumber));
		}
		System.out.println("Sort begin...");
		long current = System.currentTimeMillis();
		int[] result = Top100.getTop100(inputArray);
		System.out.println("cost time:"+(System.currentTimeMillis() - current)+"ms");
		for (int i = 0; i < result.length; ++i) {
			System.out.print(result[i] + ",");
		}
	}
}